package com.eurasia.assignment.controller.dto;

import java.time.format.DateTimeFormatter;

import com.eurasia.assignment.domain.hoj.HOJFullCaseJudgement;
import com.eurasia.assignment.domain.hoj.HOJJudgementStatus;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 判题提交记录响应DTO
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class JudgeSubmitResponse {
    private Long id;
    private Long submitterId;
    private Long problemId;
    private String problemNo;
    private String problemTitle;
    private String language;
    private HOJJudgementStatus status;
    private String statusDescription; // 状态的描述信息
    private Long runId;
    private String createdAt;
    
    private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    
    /**
     * 将领域对象转换为响应DTO
     */
    public static JudgeSubmitResponse fromDomain(HOJFullCaseJudgement judgment) {
        if (judgment == null) {
            return null;
        }
        
        return JudgeSubmitResponse.builder()
                .id(judgment.getId())
                .submitterId(judgment.getSubmitterId())
                .problemId(judgment.getProblemId())
                .problemNo(judgment.getProblemNo())
                .problemTitle(judgment.getProblemTitle())
                .language(judgment.getLanguage())
                .status(judgment.getStatus())
                .statusDescription(judgment.getStatus() != null ? judgment.getStatus().getDescription() : "未知状态")
                .runId(judgment.getRunId())
                .createdAt(judgment.getCreatedAt() != null ? judgment.getCreatedAt().format(FORMATTER) : null)
                .build();
    }
} 